package major;

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.kafka.common.serialization.StringSerializer;

import java.time.Duration;
import java.util.Arrays;
import java.util.Properties;

public class Recver {
    public static void main(String[] args) {
        Properties configs = new Properties();
        configs.put("bootstrap.servers", "192.168.0.7:9092");
        configs.put("group.id","testings");
//        configs.put("auto.offset.reset", "earliest");
        configs.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,false);
        StringDeserializer deserializer = new StringDeserializer();
        KafkaConsumer<String, String> consumer =
                new KafkaConsumer<>(configs,deserializer,deserializer);
        consumer.subscribe(Arrays.asList("test-second"));
        while (true){
            ConsumerRecords<String, String> records = consumer.poll(Duration.ofSeconds(4));
            System.out.println(" count ? "+records.count());
            for (ConsumerRecord<String, String> record : records) {
                System.out.println(record.offset()+" -- "+record.key()+" :: "+record.value());
            }

        }


    }
}
